# Script for populating the database. You can run it as:
#
#     mix run priv/repo/seeds.exs
#
# Inside the script, you can read and write to any of your
# repositories directly:
#
#     ChoicePlayground.Repo.insert!(%ChoicePlayground.SomeModel{})
#
# We recommend using the bang functions (`insert!`, `update!`
# and so on) as they will fail if something goes wrong.
alias ChoicePlayground.Repo
alias ChoicePlayground.{QuestionContent, Question, Questionnaire}

Repo.delete_all QuestionContent
Repo.delete_all Question
Repo.delete_all Questionnaire


questionnaire = Repo.insert! %Questionnaire{
  seq: 1,
  title: "程序员信仰测试"
}

question1 = Repo.insert! %Question{
  seq: 1,
  title: "请选择你最喜欢的语言",
  type: "select",
  required: true,
  questionnaire_id: questionnaire.id
}

Repo.insert! %QuestionContent{
  seq: 1,
  count: 0,
  content: "PHP",
  question_id: question1.id,
}

Repo.insert! %QuestionContent{
  seq: 2,
  count: 0,
  content: "Ruby",
  question_id: question1.id,
}

Repo.insert! %QuestionContent{
  seq: 3,
  count: 0,
  content: "Elixir",
  question_id: question1.id,
}

Repo.insert! %QuestionContent{
  seq: 4,
  count: 0,
  content: "JavaScript",
  question_id: question1.id,
}

question2 = Repo.insert! %Question{
  seq: 2,
  type: "fill",
  title: "请填写你喜欢它的原因",
  required: false,
  questionnaire_id: questionnaire.id
}

Repo.insert! %QuestionContent{
  seq: 1,
  count: 0,
  content: "",
  question_id: question2.id,
}

# question3 = Repo.insert! %Question{
#   seq: 3,
#   title: "请选择你最喜欢的语言",
#   type: "select",
#   required: true,
#   questionnaire_id: questionnaire.id
# }

# Repo.insert! %QuestionContent{
#   seq: 1,
#   count: 0,
#   content: "PHP",
#   question_id: question3.id,
# }

# Repo.insert! %QuestionContent{
#   seq: 2,
#   count: 0,
#   content: "Ruby",
#   question_id: question3.id,
# }

# Repo.insert! %QuestionContent{
#   seq: 3,
#   count: 0,
#   content: "Elixir",
#   question_id: question3.id,
# }

# Repo.insert! %QuestionContent{
#   seq: 4,
#   count: 0,
#   content: "JavaScript",
#   question_id: question3.id,
# }
